﻿<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>设备管理</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="../../../static/css/font.css">
    <link rel="stylesheet" href="../../../static/css/weadmin.css">
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>
      <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
      <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
</head>
<body>
    <div class="weadmin-nav">
        <span class="layui-breadcrumb" style="visibility: visible;">
            <a href="#">首页</a><span lay-separator="">/</span>
            <a href="#">基础数据设置</a><span lay-separator="">/</span>
            <a><cite>设备管理</cite></a>
        </span>
        <a class="layui-btn layui-btn-sm" style="line-height:1.6em;margin-top:3px;float:right" href="javascript:location.replace(location.href);" title="刷新">
            <i class="layui-icon" style="line-height:30px">ဂ</i>
        </a>
    </div>
    <div class="weadmin-body">
        <table class="layui-hide" id="roleman" lay-filter="roleman"></table>
    </div>
    <script type="text/html" id="toolbar">
        <div class="layui-btn-container">
            <!--<button class="layui-btn layui-btn-sm" lay-event="delAll"><i class="layui-icon"></i>批量删除</button>--><!--功能没做，先隐藏-->
            <button class="layui-btn layui-btn-sm" lay-event="add"><i class="layui-icon"></i>添加</button>
        </div>
    </script>
    <script id="barDemo" type="text/html">
        <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
        <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
    </script>
    <script src="../../../lib/layui/layui.js" charset="utf-8"></script>
    <script>
        var contollerName = "AttendanceDev";
        layui.use(['table', 'laydate', 'jquery', 'layer'], function () {
            var table = layui.table,
                laydate = layui.laydate,
                $ = layui.jquery,
                layer = layui.layer;
            laydate.render({
                elem: '#start',
                trigger: 'click'
            });
            laydate.render({
                elem: '#end',
                trigger: 'click'
            });
            $.support.cors = true;
            $.ajaxSetup({
                cache: false,
                headers: {
                    "userid": JSON.parse(window.localStorage.authInfo).UserId,
                    "signtoken": JSON.parse(window.localStorage.authInfo).SignToken,
                },
            })
            function showList() {
                var swhere = JSON.stringify({
                    //TPName: $("#TPName").val(),
                    //TPReleaseStart: $("#TPReleaseStart").val(),
                    //TPReleaseEnd: $("#TPReleaseEnd").val(),
                    //TPDescribe: $("#TPDescribe").val(),
                    ////TPIsRelease: $("#TPIsRelease").val(),
                    //IsUse: 1,
                    //self: 0
                });
                table.render({
                    elem: '#roleman',
                    cellMinWidth: 80,
                    toolbar: "#toolbar",
                    url: ApiUrl + contollerName + '/Search',
                    //id: "dataList",
                    headers: {
                        "userid": JSON.parse(window.localStorage.authInfo).UserId,
                        "signtoken": JSON.parse(window.localStorage.authInfo).SignToken,
                    }
                    , page: true
                    ,cols: [
                        [
                            { type: 'checkbox' },
                            { field: 'DevID', title: 'DevID', hide: true },
                            { field: 'CRID', title: 'CRID', hide: true },
                            { field: 'DevIP', title: '设备IP', sort: true},
                            { field: 'DVRIP', title: '摄像机IP', sort: true },
                            { field: 'DVRPort', title: '摄像机端口', sort: true },
                            { field: 'DVRLoginUserID', title: '用户', sort: true },
                            { field: 'DVRLoginPwd', title: '密码', sort: true },
                            { field: 'LocalPort', title: '访问端口', sort: true },
                            { field: 'CameraIP', title: '摄像头IP', sort: true },
                            { field: 'DevMac', title: 'MAC', sort: true },  
                            { fixed: 'right', title: '操作', toolbar: '#barDemo', width: 180 },
                        ]
                    ],
                    where: {swhere: swhere},
                    event: true,
                    page: true,
                    parseData: function (res) {//res 即为原始返回的数据
                        return {
                            "code": res.StatusCode, //解析接口状态
                            "msg": res.Info, //解析提示文本
                            "count": res.Count, //解析数据长度
                            "data": res.Data //解析数据列表
                        };
                    },
                    response: { statusCode: 200 },//规定成功的状态码，默认：0
                    done: function (res, curr, count) {
                        //如果是异步请求数据方式，res即为你接口返回的信息。
                        //如果是直接赋值的方式，res即为：{data: [], count: 99} data为当前页数据、count为数据总长度
                        //if (res.data != null) {
                        //    var p = $(".layui-laypage-skip").find("input[type=text]").val();
                        //    var c = $(".layui-laypage-limits select").find("option:selected").text().substring(0, 2);
                        //    var k = (Number(p) - 1) * Number(c);
                        //    for (var i = 0; i < res.data.length; i++) {
                        //        var item = res.data[i];
                        //        var ix = item.Row - 1 - k;
                        //        $(".layui-table-body table tbody tr[data-index=" + ix + "]").attr("style", dataRowColor[item.TPDepLevel]);
                        //    }
                        //}
                        //if (res.code == 403) {
                        //    layer.alert(res.msg, function () {
                        //        top.location.href = "http://" + top.location.host + "/login.html";
                        //    })
                        //}
                    }
                });
            }
            //头工具栏事件
            table.on('toolbar(roleman)', function (obj) {
                var checkStatus = table.checkStatus(obj.config.id);
                switch (obj.event) {
                    case 'delAll':
                        console.log(checkStatus.data);
                        break;
                    case 'add':
                        var add = layer.open({
                            type: 2,
                            title: "设备信息添加",
                            area: ['700px', '450px'],
                            fixed: false, //不固定
                            maxmin: true,
                            content: './AttendanceDev_add.html',
                            end: function () {
                                location.reload();
                            }
                        });
                        layer.full(add);
                        break;
                };
            });
            //监听行工具事件
            table.on('tool(roleman)', function (obj) {
                var data = obj.data;
                if (obj.event === 'del') {
                    layer.confirm('确认删除行吗?', function (index) {
                        var postdata = { "": data.DevID };
                        $.post(ApiUrl + 'AttendanceDev/Del', postdata, function (data) {
                            if (data.StatusCode == 200) {
                                obj.del();
                                layer.msg("删除成功");
                            }else{
                                layer.msg(data.Info);
                            }
                        });
                        layer.close(index);
                    });
                } else if (obj.event === 'edit') {
                    var edit = layer.open({
                        type: 2,
                        title: "设备信息编辑",
                        area: ['700px', '450px'],
                        fixed: false, //不固定
                        maxmin: true,
                        content: './AttendanceDev_edit.html?' + "DevID=" + obj.data.DevID + " &DevIP=" + obj.data.DevIP +
                            " &CRID=" + obj.data.CRID +
                            " &DVRIP=" + obj.data.DVRIP +
                            " &DVRPort=" + obj.data.DVRPort +
                            " &DVRLoginUserID=" + obj.data.DVRLoginUserID +
                            " &DVRLoginPwd=" + obj.data.DVRLoginPwd +
                            " &LocalPort=" + obj.data.LocalPort +
                            " &CameraIP=" + obj.data.CameraIP +
                            " &DevMac=" + obj.data.DevMac,
                        end: function () {
                            location.reload();
                        }
                    });
                    layer.full(edit);
                }
            });
            showList();

        });
    </script>

</body>

</html>